Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 4 - Geometric Operations / Using Geometric Operations


Determining and Reversing Contour Direction

The contours of geometric shapes have contour direction: either clockwise or counterclockwise, as described in "Contours and Contour Direction" beginning on page 4-4. QuickDraw GX allows you to determine the contour direction of a specific contour of a shape and also allows you to change the direction of a shape's contour by reversing the order of the geometric points in the geometry defining the contour.

The sample function in Listing 4-1 creates a polygon shape with two contours--one having a clockwise contour direction and the other having a counterclockwise contour direction.

Listing 4-1 Creating a polygon shape with two contours having opposite contour directions

void CreateConcentricTriangles(void)
{
   gxShape twoTriangles;

   long  twoTrianglesGeometry[] = {2, /* number of contours */
                                   3, /* number of points */
                                   ff(50), ff(200),
                                   ff(110), ff(100),
                                   ff(170), ff(200), 
                                   3, /* number of points */
                                   ff(90), ff(178),
                                   ff(130), ff(178),
                                   ff(110), ff(145)};
   
   twoTriangles = GXNewPolygons((gxPolygons *) 
                                 twoTrianglesGeometry);
   GXSetShapeFill(twoTriangles, gxWindingFill);
   GXDrawShape(twoTriangles);
   GXDisposeShape(twoTriangles);
}
The result of this sample function is shown in Figure 4-17.

Figure 4-17 A polygon shape whose two contours have opposite contour directions

QuickDraw GX provides the GXGetShapeDirection function to allow you to determine the contour direction of a specific contour in a shape. This function takes two parameters: the first parameter is a reference to the shape and the second parameter is the index of the contour whose contour direction you want to find. In the example from Listing 4-1, the first contour (the outer contour) has a clockwise contour direction. Calling the function

GXGetShapeDirection(twoTriangles, 1);
returns the constant gxClockwiseDirection.

The second contour (the inner contour) has a counterclockwise direction. Calling the function

GXGetShapeDirection(twoTriangles, 2);
returns the constant gxCounterclockwiseDirection.

You can reverse the direction of a contour by reversing the order of the contour's geometric points. For this purpose, QuickDraw GX provides the GXReverseShape function. This function also takes two parameters: a reference to the shape and the index of the contour to reverse. Specifying 0 as the number of the contour to reverse causes the GXReverseShape function to reverse all the contours of a shape. For example, you can add the following function call to the sample function in Listing 4-1:

GXReverseShape(twoTriangles, 0);
The result is shown in Figure 4-18.

Figure 4-18 A polygon shape with the direction of both contours reversed

Since both contours are reversed in this example, the shape appears the same when drawn as it did before the contours were reversed.

However, reversing only the inner contour of this polygon by calling

GXReverseShape(twoTriangles, 2);
results in the polygon shown in Figure 4-19.

Figure 4-19 A polygon shape with the direction of the inner contour reversed

Reversing the contour of a shape by calling the GXReverseShape function almost always changes the result of the GXGetShapeDirection function. One important exception, however, is that line shapes always have a clockwise direction. The order of a line shape's geometric points does not affect the result of the GXGetShapeDirection function.

For a discussion of contour direction, see "Contours and Contour Direction" beginning on page 4-4.

For more information about the GXGetShapeDirection function, see page 4-68. For more information about the GXReverseShape function, see page 4-70.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996